package com.zat.mes.andrmes.dofun.system.adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.BaseAdapter
import android.widget.TextView
import com.zat.mes.andrmes.R
import com.zat.mes.andrmes.data.ComResultBean

/**
 * @author zy
 * @date :2020-03-23 11:07
 * @description:企业列表adapter
 */
class CompanyAdapter(context: Context, list: MutableList<ComResultBean>) : BaseAdapter() {
    val context = context
    val dataList: MutableList<ComResultBean>? = list
    override fun getView(position: Int, convertView: View?, parent: ViewGroup?): View {
        var viewHolder: ViewHolder? = null
        var view: View? = null
        if (convertView == null) {
            viewHolder = ViewHolder()
            view = LayoutInflater.from(context).inflate(R.layout.item_company, null)
            viewHolder.textView = view.findViewById(R.id.company_item)
            view.tag = viewHolder
        } else {
            view = convertView
            viewHolder = view.tag as ViewHolder
        }

        viewHolder.textView?.text = dataList?.get(position)?.corpName
        return view!!
    }

    override fun getItem(position: Int): ComResultBean? {
        return dataList?.get(position)
    }

    override fun getItemId(position: Int): Long {
        return position.toLong()
    }

    override fun getCount(): Int {
        return dataList?.size!!
    }

    class ViewHolder {
        var textView: TextView? = null
    }

}